<%@ page import="com.ld.businessCard.service.UserService" %>
<%@ page import="com.ld.businessCard.service.impl.UserServiceImpl" %>
<%@ page import="com.ld.businessCard.entity.User" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-10
  Time: 8:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户管理</title>
    <style>
        td {
            color: #ff4b2b;
            text-align: center;
        }
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        a {
            text-decoration: none;
            color: black;
        }
        .container {
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35), 0 10px 10px rgba(0, 0, 0, 0.22);
            position: relative;
            overflow: hidden;
            width: 768px;
            max-width: 100%;
            min-height: 480px;
            margin:0 auto;
        }
    </style>
</head>
<body>
<%!
    private UserService userService= new UserServiceImpl();
%>
<%
    List<User> users = userService.getAllUsers();
    String homePath;
    User user0 = (User)session.getAttribute("user");
    if(user0.getStatus() == 0){
        homePath = "user";
    }else {
        homePath = "admin";
    }
    out.println("<a href='/home/"+homePath + "/index.jsp'" + "  style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回个人管理页面</a><br>");
    if (users.isEmpty()) out.println("<h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!<h1>");
    else {
        out.println("<table class='container'>" +
                "<tr>" +
                "<th>用户ID</th>" +
                "<th>用户名</th>" +
                "<th>账号</th>" +
                "<th>操作</th>" +
                "</tr>");
        if (!users.isEmpty())
            for (User user : users) {
                String deleteDOM = "<td><a class='deleteUser' href=" + "'/user/delete?id=" + user.getId() + "'>删除" + "</a></td>";
                out.println("<tr>");
                out.println("<td>" + user.getId() + "</td>");
                out.println("<td>" + user.getUsername() + "</td>");
                out.println("<td>" + user.getAccount() + "</td>");
                out.println(deleteDOM);
                out.println("</tr>");
            }
        out.println("</table>");
    }
%>
</body>
<script>
    let deleteU = document.getElementsByClassName("deleteUser");
    for (let i = 0; i < deleteU.length; i++) {
        deleteU[i].addEventListener("click",(e) => {
            var b = confirm("你确定要删除吗?");
            if(b == false){
                e.preventDefault();
            }
        })
    }
</script>
</html>
